<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
    <div class="container-div">
    	<div class="row">
    		<div class="col-sm-12 select-info">
				<form id="operlog-form">
					<input type="hidden" name="remark" value="0">
					<div class="select-list gd">
						<ul>
							<li>
								异常状态：<select name="status">
									<option value="">所有</option>
									<option value="1">未入校</option>
									<option value="2">提前入校</option>
									<option value="3">迟到</option>
									<option value="4">提前出校</option>
									<option value="5">出校超时</option>
									<option value="6">未出校</option>
								</select>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search($('form').attr('id'))"><i class="fa fa-search"></i>&nbsp;搜索</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
	        <div class="col-sm-12 select-info order-table">
		        <table id="bootstrap-table" data-mobile-responsive="true">
		        </table>
	        </div>
	    </div>
    </div>
    <div th:include="include :: footer"></div>
    <script th:inline="javascript">
        var prefix = ctx + "module/abnormal"

        $(function() {
            var options = {
                url: prefix + "/list",
                modalName: "进出异常记录",
                search: false,
		        showExport: false,
                columns: [{
		            checkbox: true
		        },
		        {
		            title: '序号',
		            field: '',
		            align: 'center',
		            formatter: function (value, row, index) {
		                var pageSize = $('#bootstrap-table').bootstrapTable('getOptions').pageSize;     //通过table的#id 得到每页多少条
		                var pageNumber = $('#bootstrap-table').bootstrapTable('getOptions').pageNumber; //通过table的#id 得到当前第几页
		                return pageSize * (pageNumber - 1) + index + 1;    // 返回每条的序号： 每页条数 *（当前页 - 1 ）+ 序号
		            }
		        },
				{
					field : 'inOutDate', 
					align: 'center',
					title : '异常日期' 
				},
				{
					field : 'studentNumber',
					align: 'center',
					title : '学号' 
				},
				{
					field : 'student.name', 
					align: 'center',
					title : '姓名' 
				},
				{
					field : 'student.classes.name', 
					align: 'center',
					title : '所在班级' 
				},
				{
					field : 'student.classes.headmasterId', 
					align: 'center',
					title : '班主任' 
				},
				{
					field : '', 
					align: 'center',
					title : '家长1',
					formatter: function(value, row, index) {
						if(row.student.parents.length>0){
						return row.student.parents[0].name+"("+getAppellation(row.student.parents[0].appellation)+")";
						}
		            }
				},
				{
					field : '', 
					align: 'center',
					title : '联系电话' ,
					formatter: function(value, row, index) {
						if(row.student.parents.length>0){
						return row.student.parents[0].telephone;
						}
		            }
				},
				{
					field : '', 
					align: 'center',
					title : '家长2',
					formatter: function(value, row, index) {
						if(row.student.parents.length>1){
						return row.student.parents[1].name+"("+getAppellation(row.student.parents[1].appellation)+")";
						}
		            }
				},
				{
					field : '', 
					align: 'center',
					title : '联系电话' ,
					formatter: function(value, row, index) {
						if(row.student.parents.length>1){
						return row.student.parents[1].telephone;
						}
		            }
				},
				{
					field : 'status', 
					title : '异常状态',
					align: 'center',
					formatter: function(value, row, index) {
						if (value == '1') {
		                    return '<span class="badge badge-danger">未入校</span>';
		                } else if (value == '2') {
		                    return '<span class="badge badge-danger">提前入校</span>';
		                } else if (value == '3') {
		                    return '<span class="badge badge-warning">迟到</span>';
		                } else if (value == '4') {
		                    return '<span class="badge badge-warning">提前出校</span>';
		                } else if (value == '5') {
		                    return '<span class="badge badge-danger">出校超时</span>';
		                } else if (value == '6') {
		                    return '<span class="badge badge-danger">未出校</span>';
		                }else{
		                    return '<span class="badge badge-white">正常进出</span>';
		                }
		            }
				},
				{
					field : 'remarks', 
					align: 'center',
					title : '异常明细' 
				},
				{
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var status = row.status;
		            	if(status != '1' || status != '6'){
			            	var actions = [];
			            	actions.push('<a class="btn btn-success btn-xs" href="#" onclick="openImg(\'' + row.url + '\')"><i class="fa fa-edit"></i>查看图片</a> ');
							return actions.join('');
		            	}
		            }
		        }]
            };
            $.table.init(options);
        });
        
        function getAppellation(id){
        	var s = "";
        	switch (id){
        		case "1":
        			s = "父亲";
        			break;
        		case "2":
        			s = "母亲";
        			break;
        		case "3":
        			s = "爷爷";
        			break;
        		case "9":
        			s = "家长";
        			break;
        		default:
        			s = id;
        	}
        	return s;
        }
        
        function openImg(url){
        	layer.open({
       	      type: 2,
      	   	  title: "学生进出图片", 
       	      shadeClose: true,
       	      shade: true,
       	      maxmin: true, //开启最大化最小化按钮
       	      area: ['800px', '400px'],
       	   	  content: url
       	    });
        }
    </script>
</body>
</html>